package com.chinairi.mall.service.impl;

import com.chinairi.mall.controller.viewobject.ProjectPlanReqVO;
import com.chinairi.mall.error.BusinessException;
import com.chinairi.mall.error.EmBusinessError;
import com.chinairi.mall.model.ProjectPlanReqStorage;
import com.chinairi.mall.dao.ProjectPlanReqStorageMapper;
import com.chinairi.mall.model.StorageAddress;
import com.chinairi.mall.service.IProjectPlanReqStorageService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.chinairi.mall.service.modelobject.ProjectPlanReqStorageMO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author Webgasd
 * @since 2020-10-15
 */
@Service
public class ProjectPlanReqStorageServiceImpl extends ServiceImpl<ProjectPlanReqStorageMapper, ProjectPlanReqStorage> implements IProjectPlanReqStorageService {

    @Autowired
    private ProjectPlanReqStorageMapper projectPlanReqStorageMapper;
    @Autowired
    private ProjectPlanPickingServiceImpl projectPlanPickingService;

    /**
     * 根据所选物料组筛选库点组
     *
     *
     * @param projectPlanReqVO @return
     * @return
     */
    @Override
    public List<StorageAddress> selectStorageList(ProjectPlanReqVO projectPlanReqVO) {
        List<String> matCodeList = projectPlanPickingService.getMatDbIdList(projectPlanReqVO.getProjectPlanReqDetailList());
        if(matCodeList.size() == 0){
            throw new BusinessException(EmBusinessError.PARAMETER_VALIDATION_ERROR, "选中物料未进行平库或平库数不足！");
        }
        return projectPlanReqStorageMapper.selectStorageList(matCodeList, projectPlanReqVO.getPlanReqId());
    }

    /**
     * 获取平库列表
     * @param projectPlanReqStorage
     * @return
     */
    @Override
    public List<ProjectPlanReqStorageMO> getStorageFlatList(ProjectPlanReqStorage projectPlanReqStorage) {
        return projectPlanReqStorageMapper.getStorageFlatList(projectPlanReqStorage.getPlanReqId(), projectPlanReqStorage.getPlanMatCode());
    }
}
